<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /**
     * 给你一个字符串 s ，字符串的「能量」定义为：只包含一种字符的最长非空子字符串的长度。
     * 请你返回字符串的能量。
     * @param {string} s
     * @return {number}
     */
    var maxPower = function(s) {
      let arr = s.split("")
      let before = arr[0]
      let len = 1
      let res = 1
      for(let i=1; i<arr.length; i++){
          if(before === arr[i]){
            len +=1
          }else{
            if(len>res) res = len
            before = arr[i]
            len = 1
          }
      }
      if(len>res) res = len
      return res
    };
    // 不用存储before,不转换arr
    var maxPower2 = function(s) {
      let len = 1
      let res = 1
      for(let i=1; i<s.length; i++){
          if(s[i-1] === ss[i]){
            ++len
            res = Math.max(res,len) //取大值
          }else{
            len = 1
          }
      }
      return res
    };

  </script>
</body>
</html>